import java.util.Scanner;
import java.util.Stack;

/**
 * @author gao
 * @date 2025/9/3 13:50
 */

public class Solution {
    public int calPoints(String[] operations) {
        Stack<Integer> stack = new Stack<>();
        for (String op : operations) {
            if (op.equals("+")) {
                // 获取栈顶两个元素
                int top = stack.pop();
                int newTop = stack.peek() + top;
                stack.push(top); // 把先前弹出的元素压回去
                stack.push(newTop); // 再压入新的和
            } else if (op.equals("D")) {
                // 获取栈顶元素的两倍
                stack.push(2 * stack.peek());
            } else if (op.equals("C")) {
                // 移除栈顶元素
                stack.pop();
            } else {
                // 数字直接压入
                stack.push(Integer.valueOf(op));
            }
        }

        // 求总分
        int sum = 0;
        for (int score : stack) {
            sum += score;
        }
        return sum;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            in.nextLine();
            String[] ops = new String[n];
            for (int i = 0; i < ops.length; i++) {
                ops[i] = in.nextLine();
            }
            Solution solution = new Solution();
            System.out.println(solution.calPoints(ops));
        }
    }
}